package com.ryskoo.controller.basicdata;

import com.ryskoo.basicdata.weixin.domain.WeixinParamPO;
import com.ryskoo.basicdata.weixin.service.IWeixinParamService;
import com.ryskoo.common.dto.basicdata.LogoDTO;
import com.ryskoo.framework.core.bean.ReturnMessageDTO;
import com.ryskoo.framework.core.controller.BasicHandler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

/**
 * 微信参数设置
 * @author BeHappy
 */
@Controller
@RequestMapping("/vendor/basicdata/weixinparam")
public class WeixinParamController extends BasicHandler<WeixinParamPO> {
	
    private static final String TEMPLATE_PATH = "system/basicdata/weixinparam";

    private static final String MODULE_NAME = "WeixinParam";

    private IWeixinParamService weixinParamService;
    
    /**
     * 基类构造方法.
     */
    public WeixinParamController() {
        super(TEMPLATE_PATH, MODULE_NAME);
    }

    /**
     * 消费者注入
     *
     * @param weixinParamConsumer 消费者基类
     */
    @Autowired
    protected void setService(IWeixinParamService weixinParamService) {
        this.weixinParamService = weixinParamService;
        super.setService(weixinParamService);
    }

    /**
     * 跳转列表页
     *
     * @return 页面模板路径
     */
    @GetMapping("/tosetting")
    public String toSetting(Model model, HttpServletRequest request) {
    	List<WeixinParamPO> list = weixinParamService.getAll();
    	WeixinParamPO po = null;
    	if(list != null && list.size() > 0){
    		po = list.get(0);
		}
        model.addAttribute("dto", po);
        return TEMPLATE_PATH + "/" + MODULE_NAME + "Setting";
    }

    
    /**
     * 编辑
     *
     * @param dto
     *            编辑的对象 {@link LogoDTO}
     * @return 统一返回消息 {@link ReturnMessageDTO}
     */
    @PostMapping("/setting")
    @ResponseBody
    public ReturnMessageDTO setting(@RequestBody WeixinParamPO po) {
        return super.edit(po);
    }
}
